package com.sanq.product.mcgs.service.impl;

import com.sanq.product.mcgs.entity.vo.LogsVo;
import com.sanq.product.config.utils.entity.Pager;
import com.sanq.product.config.utils.entity.Pagination;
import com.sanq.product.mcgs.service.LogsService;
import com.sanq.product.mcgs.mapper.LogsMapper;
import java.util.List;
import java.math.BigDecimal;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;


@Service("logsService")
public class LogsServiceImpl implements LogsService {

	@Resource
	private LogsMapper logsMapper;
	
	@Override
	public int save(LogsVo logsVo) {
		return logsMapper.save(logsVo);
	}
	
	@Override
	public int delete(LogsVo logsVo) {
		return logsMapper.delete(logsVo);
	}	
	
	@Override
	public int update(LogsVo logsVo, Integer logId) {
		LogsVo oldLogsVo = findById(logId);
		
		if(null != oldLogsVo && null != logsVo) {
			if(null != logsVo.getLogId()) {
				oldLogsVo.setLogId(logsVo.getLogId());
			}
			if(null != logsVo.getException()) {
				oldLogsVo.setException(logsVo.getException());
			}
			if(null != logsVo.getMethod()) {
				oldLogsVo.setMethod(logsVo.getMethod());
			}
			if(null != logsVo.getOperateDate()) {
				oldLogsVo.setOperateDate(logsVo.getOperateDate());
			}
			if(null != logsVo.getParams()) {
				oldLogsVo.setParams(logsVo.getParams());
			}
			if(null != logsVo.getRemoteAddr()) {
				oldLogsVo.setRemoteAddr(logsVo.getRemoteAddr());
			}
			if(null != logsVo.getRequestUri()) {
				oldLogsVo.setRequestUri(logsVo.getRequestUri());
			}
			if(null != logsVo.getTimeout()) {
				oldLogsVo.setTimeout(logsVo.getTimeout());
			}
			if(null != logsVo.getTitle()) {
				oldLogsVo.setTitle(logsVo.getTitle());
			}
			if(null != logsVo.getType()) {
				oldLogsVo.setType(logsVo.getType());
			}
			if(null != logsVo.getUserId()) {
				oldLogsVo.setUserId(logsVo.getUserId());
			}
			if(null != logsVo.getLoginName()) {
				oldLogsVo.setLoginName(logsVo.getLoginName());
			}
			return logsMapper.update(oldLogsVo);
		}
		return 0;
	}
	
	@Override
	public LogsVo findById(Integer logId) {
		return logsMapper.findById(logId);
	}
	
	@Override
	public List<LogsVo> findList(LogsVo logsVo) {
		return logsMapper.findList(logsVo);
	}
	
	@Override
	public Pager<LogsVo> findListByPage(LogsVo logsVo,Pagination pagination) {
		pagination.setTotalCount(findCount(logsVo));
		
		List<LogsVo> datas = logsMapper.findListByPage(logsVo,pagination.getStartPage(),pagination.getPageSize());
		
		return new Pager<LogsVo>(pagination,datas);
	}
	
	@Override
	public int findCount(LogsVo logsVo) {
		return logsMapper.findCount(logsVo);
	}
	
	@Override
	public void saveByList(List<LogsVo> logsVos) {
		logsMapper.saveByList(logsVos);
	}
}